//
//  UserBSRegister.m
//  Teacher
//
//  Created by 马腾飞 on 15/7/28.
//  Copyright (c) 2015年 xueyinyue. All rights reserved.
//

#import "UserBSRegister.h"
#import "ApplicationContext.h"
#import "ApiConfig.h"

@implementation UserBSRegister{
    
    
}

- (id)onExecute {
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:_phoneNum forKey:@"phone"];
    [params setObject:kSystemType forKey:@"systemType"];
    [params setObject:kVersionCode forKey:@"versionCode"];
    [params setObject:_InputVerificationCode forKey:@"proving"];
    [params setObject:_getVerificationCode forKey:@"code"];
    [params setObject:_password forKey:@"password"];
    
    id result = [self remoteJSON:@"POST" url:[ApiConfig urlApiUserRegister] params:params];
    
    UserBSRegisterResult *serviceResult = [[UserBSRegisterResult alloc]  init];
    
    NSNumber *returnState = result[@"error"];
    //成功时进行注册
    if ([returnState isEqualToNumber:@0]) {
        
        serviceResult.isRegisterSuccess = YES;
        
        NSLog(@"注册成功%@",result[@"data"][@"token"]);
        
        [ApplicationContext instance].token = result[@"data"][@"token"];
        
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:[ApplicationContext instance].token forKey:@"token"];
        
        
        NSLog(@"用户里的%@",[ApplicationContext instance].token);
    }
    else
    {
        serviceResult.isRegisterSuccess = NO;
        serviceResult.message = result[@"msg"];
    }
    
    return serviceResult;
}

@end

@implementation UserBSRegisterResult{
    
}

@end
